package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocPunishDao;
import com.irdstudio.cdp.pboc.service.domain.PbocPunish;
import com.irdstudio.cdp.pboc.service.facade.PbocPunishService;
import com.irdstudio.cdp.pboc.service.vo.PbocPunishVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 行政处罚记录				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocPunishService")
public class PbocPunishServiceImpl implements PbocPunishService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocPunishServiceImpl.class);

	@Autowired
	private PbocPunishDao pbocPunishDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocPunish(PbocPunishVO inPbocPunishVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocPunishVo.toString());
		int num = 0;
		try {
			PbocPunish pbocPunish = new PbocPunish();
			beanCopy(inPbocPunishVo, pbocPunish);
			num = pbocPunishDao.insertPbocPunish(pbocPunish);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocPunishVO inPbocPunishVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocPunishVo);
		int num = 0;
		try {
			PbocPunish pbocPunish = new PbocPunish();
			beanCopy(inPbocPunishVo, pbocPunish);
			num = pbocPunishDao.deleteByPk(pbocPunish);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocPunishVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocPunishVO inPbocPunishVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocPunishVo.toString());
		int num = 0;
		try {
			PbocPunish pbocPunish = new PbocPunish();
			beanCopy(inPbocPunishVo, pbocPunish);
			num = pbocPunishDao.updateByPk(pbocPunish);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocPunishVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocPunishVO queryByPk(PbocPunishVO inPbocPunishVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocPunishVo);
		try {
			PbocPunish queryPbocPunish = new PbocPunish();
			beanCopy(inPbocPunishVo, queryPbocPunish);
			PbocPunish queryRslPbocPunish = pbocPunishDao.queryByPk(queryPbocPunish);
			if (Objects.nonNull(queryRslPbocPunish)) {
				PbocPunishVO outPbocPunishVo = beanCopy(queryRslPbocPunish, new PbocPunishVO());
				logger.debug("当前查询结果为:"+ outPbocPunishVo.toString());
				return outPbocPunishVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocPunishVO> queryAllOwner(PbocPunishVO pbocPunishVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocPunishVO> list = null;
		try {
			List<PbocPunish> pbocPunishs = pbocPunishDao.queryAllOwnerByPage(pbocPunishVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocPunishs.size());
			pageSet(pbocPunishs, pbocPunishVo);
			list = (List<PbocPunishVO>) beansCopy(pbocPunishs, PbocPunishVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocPunishVO> queryAllCurrOrg(PbocPunishVO pbocPunishVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocPunish> pbocPunishs = pbocPunishDao.queryAllCurrOrgByPage(pbocPunishVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocPunishs.size());
		List<PbocPunishVO> list = null;
		try {
			pageSet(pbocPunishs, pbocPunishVo);
			list = (List<PbocPunishVO>) beansCopy(pbocPunishs, PbocPunishVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocPunishVO> queryAllCurrDownOrg(PbocPunishVO pbocPunishVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocPunish> pbocPunishs = pbocPunishDao.queryAllCurrDownOrgByPage(pbocPunishVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocPunishs.size());
		List<PbocPunishVO> list = null;
		try {
			pageSet(pbocPunishs, pbocPunishVo);
			list = (List<PbocPunishVO>) beansCopy(pbocPunishs, PbocPunishVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
}
